import { logger } from '$common';
import { osInfoReport } from '$domain/model/agent/agentService';
import { OsUtils } from './osUtils';
import { agentConfig } from '$domain/model/agent/config';


export class OsReportService {

  init() {
    const osutil = new OsUtils();

    if (agentConfig.osInfoEnable) {
      const interval = agentConfig.osInfoInterval || 60000;
      setInterval(async () => {
        try {
          const cpuInfo = await osutil.getCpuInfo();
          const driveInfo = osutil.getDriveInfo();
          const memoryInfo = await osutil.getMemoryInfo();
          const osData = {
            'cpu': cpuInfo,
            'drive': driveInfo,
            'memory': memoryInfo
          };
          await osInfoReport(osData);
        } catch (e) {
          logger.warn(`os info report error: ${e}`);
        }
      }, interval);
    }
  }
}